#ifndef __AT24C16__P_H
#define __AT24C16__P_H

#include "at24c16.h"

#include "mcu.h"

#define AT24C16_SDA_CLK      RCC_AHB1Periph_GPIOB
#define AT24C16_SDA_PORT     GPIOB
#define AT24C16_SDA_PIN      GPIO_Pin_1

#define AT24C16_SCL_CLK      RCC_AHB1Periph_GPIOB
#define AT24C16_SCL_PORT     GPIOB
#define AT24C16_SCL_PIN      GPIO_Pin_0


void AT24C16_Board_Init()
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    RCC_AHB1PeriphClockCmd( AT24C16_SDA_CLK,ENABLE);
    RCC_AHB1PeriphClockCmd( AT24C16_SCL_CLK, ENABLE);

    // Configure I2C1 pins: SCL and SDA
    GPIO_InitStructure.GPIO_Pin =  AT24C16_SDA_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(AT24C16_SDA_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin =  AT24C16_SCL_PIN;
    GPIO_Init(AT24C16_SCL_PORT, &GPIO_InitStructure);
}

void AT24C16_Board_SCL(BitAction bitstatus)
{
	if ( bitstatus == Bit_RESET )
	{
		GPIO_ResetBits(AT24C16_SCL_PORT,AT24C16_SCL_PIN);
	}
	else
	{
		GPIO_SetBits(AT24C16_SCL_PORT,AT24C16_SCL_PIN);
	}
}

void AT24C16_Board_SDA(BitAction bitstatus)
{
	if ( bitstatus == Bit_RESET )
	{
		GPIO_ResetBits(AT24C16_SDA_PORT,AT24C16_SDA_PIN);
	}
	else
	{
		GPIO_SetBits(AT24C16_SDA_PORT,AT24C16_SDA_PIN);
	}
}

BitAction AT24C16_Board_SDA_Read()
{
	return (BitAction)(GPIO_ReadInputDataBit(AT24C16_SDA_PORT,AT24C16_SDA_PIN));
}

const I2C_SW_Handle _at24c16_hanlde =
{
	AT24C16_Board_Init,
	AT24C16_Board_SCL,
	AT24C16_Board_SDA,
	AT24C16_Board_SDA_Read
};


#endif
